namespace Viyi.Strings.Codec.Base32;

static class Base32ReverseCharset {
    public static readonly long[] Codes = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     // (count 16)
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     // (count 16)
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     // (count 16)
        -1, -1, 26, 27, 28, 29, 30, 31, -1, -1,     // [0~9] 48~57 (count 10)
        -1, -1, -1, -1, -1, -1, -1,                 // ASCII 58~64 (count 7)
        0, 1, 2, 3, 4, 5, 6,                        // [A~G] 65~71 (count 7)
        7, 8, 9, 10, 11, 12, 13,                    // [H~N] 72~78 (count 7)
        14, 15, 16, 17, 18, 19,                     // [O~T] 79~84 (count 6)
        20, 21, 22, 23, 24, 25,                     // [U~Z] 85~90 (count 6)
        -1, -1, -1, -1, -1, -1,                     // ASCII 91~96
        0, 1, 2, 3, 4, 5, 6,                        // [a~g] 97~103 (count 7)
        7, 8, 9, 10, 11, 12, 13,                    // [h~n] 104~110 (count 7)
        14, 15, 16, 17, 18, 19,                     // [o~t] 111~116 (count 6)
        20, 21, 22, 23, 24, 25,                     // [u~z] 117~122 (count 6)
    };

    public static bool IsValid(char ch) =>
        ch >= 50 && ch <= 122 && Codes[ch] != -1;
}

static class Base32HexReverseCharset {
    public static readonly long[] Codes = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     // (count 16)
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     // (count 16)
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     // (count 16)
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9,               // [0~9] 48~57 (count 10)
        -1, -1, -1, -1, -1, -1, -1,                 // ASCII 58~64 (count 7)
        10, 11, 12, 13, 14, 15, 16,                 // [A~G] 65~71 (count 7)
        17, 18, 19, 20, 21, 22, 23,                 // [H~N] 72~78 (count 7)
        24, 25, 26, 27, 28, 29,                     // [O~T] 79~84 (count 6)
        30, 31, -1, -1, -1, -1,                     // [U~Z] 85~90 (count 6)
        -1, -1, -1, -1, -1, -1,                     // ASCII 91~96
        10, 11, 12, 13, 14, 15, 16,                 // [a~g] 97~103 (count 7)
        17, 18, 19, 20, 21, 22, 23,                 // [h~n] 104~110 (count 7)
        24, 25, 26, 27, 28, 29,                     // [o~t] 111~116 (count 6)
        30, 31, -1, -1, -1, -1,                     // [u~z] 117~122 (count 6)
    };

    public static bool IsValid(char ch) =>
        ch >= 48 && ch <= 122 && Codes[ch] != -1;
}
